package cn.mason.echarts.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

/**
 * @author Mason
 * @date 2018/6/7
 */
@Controller
public class DataController {
    @RequestMapping(value = "/arraydata",method = RequestMethod.POST)
    @ResponseBody
    public String drawMap(@RequestParam("data")MultipartFile data){
        try {
            InputStream inputStream=data.getInputStream();
            BufferedReader reader = new BufferedReader(
                    new InputStreamReader(inputStream));
            String result = "";
            while (true) {
                String str = reader.readLine();
                if(str!=null){
                    result+=str;
                } else{
                    break;
                }
            }
            return  result;
        }catch (IOException e){
            return null;
        }
    }

    @RequestMapping(value = "/statistical",method = RequestMethod.POST)
    @ResponseBody
    public String statistical(@RequestParam("data")MultipartFile data){
        try {
            InputStream inputStream=data.getInputStream();
            BufferedReader reader = new BufferedReader(
                    new InputStreamReader(inputStream));
            String result = "";
            while (true) {
                String str = reader.readLine();
                if(str!=null){
                    result+=str;
                } else{
                    break;
                }
            }

            return  result;

        }catch (IOException e){
            return null;
        }
    }


}
